home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / stat.c < prev    next >
C/C++ Source or Header  |  1990-11-23  |  947b  |  47 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3. #include <types.h>
  4. #include <stat.h>
  5. #include <errno.h>
  6.  
  7. static    struct stat    _dta;        /* local DTA buffer */
  8.  
  9. int access(name, amode)
  10.     char *name;
  11.     int amode;
  12.     {
  13.     register struct stat *_pdta;        /* pointer to old DTA */
  14.  
  15.     _pdta = (struct stat *) Fgetdta();
  16.     Fsetdta(&_dta);
  17.     amode = ((amode & 0x02) ? 0x16 : 0x17);
  18.     errno = ((int) Fsfirst(name, amode));
  19.     Fsetdta(_pdta);
  20.     return(errno == 0);
  21.     }
  22.  
  23. int stat(name, statbuf)
  24.     register char *name;
  25.     register struct stat *statbuf;
  26.     {
  27.     if(access(name, 0x00))
  28.         {
  29.         *statbuf = _dta;
  30.         statbuf->st_mode |= ((statbuf->st_mode & S_ISRO) ?
  31.             S_IREAD : (S_IREAD | S_IWRITE));
  32.         statbuf->st_dev = ((name[1] == ':') ?
  33.             ((name[0] | 0x20) - 'a') : ((dev_t) Dgetdrv()));
  34.         statbuf->st_nlink = 1;
  35.         return(0);
  36.         }
  37.     return(ERROR);
  38.     }
  39.  
  40. long fsize(name)
  41.     char *name;
  42.     {
  43.     if(access(name, 0x00))
  44.         return(_dta.st_size);
  45.     return(ERROR);
  46.     }
  47.